package games.mapacman.common;

import games.mapacman.client.GameScreen;
import games.mapacman.server.MaPacmanZone;
import marauroa.common.game.RPClass;
import marauroa.common.game.RPObject;
import marauroa.common.game.Definition.Type;
import marauroa.server.game.Statistics;

public class EatenSign {

	
	protected int x,y;
	private int disappear;
	protected MaPacmanZone zone;
	protected RPObject myObject;
	
	public EatenSign(int x, int y, MaPacmanZone zone) {
		disappear=-1;
		myObject = new RPObject();
		myObject.put("type",consts.TYPE_EATENSIGN);
		myObject.put("x",x);
		myObject.put("y",y);
		myObject.put("delete",6);
		myObject.put("zoneid",zone.getName());
		this.x=x;
		this.y=y;
		this.zone=zone;
	}

	public EatenSign(RPObject object)
	{
		disappear=6;
		myObject = object;
		x=object.getInt("x");
		y=object.getInt("y");
	}
	
	public static void initRPClass()
	{
		 RPClass sign = new RPClass(consts.TYPE_EATENSIGN);
		 sign.isA("position");
		 sign.addAttribute("delete", Type.INT);
	}

	public RPObject getRPObject() {
		return myObject;
	}

	public int getX() {
		return myObject.getInt("x");
	}
	public int getY() {
		return myObject.getInt("y");
	}

	public boolean checkDelete() {
		myObject.put("delete",myObject.getInt("delete")-1);
		zone.getWorld().modify(myObject);
		return (myObject.getInt("delete")<1);
	}


	public void draw(GameScreen screen) {
		if (myObject.getInt("delete")<2)
		{
			if (disappear>4)
				screen.draw(screen.getKillSprite(1),x,y);
			else
				screen.draw(screen.getKillSprite(2),x,y);
			disappear--;
		}
		else
			screen.draw(screen.getKillSprite(0),x,y);
				
	}
	
	public boolean valid()
	{
		return (disappear>0);
	}


}
